const blockChainApp = require("../BlockChainApp")
const Config = require("../Config")

// 病例报告合约
module.exports = {
    // 新增处方
    addPrescription: async function(param){
        var prescriptionContarct = await blockChainApp.contracts.Prescription.deployed()
        //createPrescription(uint32 _caseRecordId, string memory _judge, string memory _dealPolicy, string memory _decisionDoctor)
        return prescriptionContarct.createPrescription(param.caseRecordId, param.judge, param.dealPolicy, param.decisionDoctor, param.dealTime, {from: Config.executeAccount})
    },

    // 更新处方
    updatePrescription: async function(param){
        var prescriptionContarct = await blockChainApp.contracts.Prescription.deployed()
        //updatePrescription(uint32 _id, uint32 _caseRecordId, string memory _judge, string memory _dealPolicy, string memory _decisionDoctor)
        return prescriptionContarct.updatePrescription(param.id, param.caseRecordId, param.judge, param.dealPolicy, param.decisionDoctor, param.dealTime, param.price, {from: Config.executeAccount})
    },

    // 查看所有处方
    getAllPrescrition: async function(param){
        var prescriptionContarct = await blockChainApp.contracts.Prescription.deployed()
        return prescriptionContarct.findAllPrescription.call()
    },

    // 条件查询处方
    getPrescriptionWithCondition: async function(param){
        var prescriptionContarct = await blockChainApp.contracts.Prescription.deployed()
        //findPrescriptionWithParam(uint32 _caseRecordId, string memory _judge, string memory _decisionDoctor, int _startDealTime, int _endDealTime)
        return prescriptionContarct.findPrescriptionWithParam.call(param.caseRecordId, param.judge, param.decisionDoctor, param.startDealTime, param.endDealTime)
    }
}